package com.chpro.scsw.service.impl;

import com.chpro.common.JSONUtils;
import com.chpro.scsw.dao.IArticleDao;
import com.chpro.scsw.model.ArticleModel;
import com.chpro.scsw.service.IArticleService;
import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

@Service("articleServiceImpl")
public class ArticleServiceImpl implements IArticleService
{
    private static final Logger log = Logger.getLogger(ArticleServiceImpl.class);
    private IArticleDao articleDao;

    @Resource(name="articleDaoImpl")
    public void setArticleDao(IArticleDao articleDao)
    {
        this.articleDao = articleDao;
    }

    public ArticleModel queryArticleById(ArticleModel articleId) throws Exception {
        this.articleDao.updateArticleById(articleId);
        return this.articleDao.queryArticleById(articleId);
    }

    public List<ArticleModel> queryArticleNew() throws Exception
    {
        return this.articleDao.queryArticleNew();
    }

    public List<ArticleModel> queryArticleHeat() throws Exception
    {
        return this.articleDao.queryArticleHeat();
    }

    public List<ArticleModel> queryArticleAll(ArticleModel articleModel)
            throws Exception
    {
        log.info(JSONUtils.toJSON(articleModel));
        int count = this.articleDao.queryArticleCount(articleModel);
        log.info("count:" + count);
        articleModel.setRowNum(Integer.valueOf(count % articleModel.getPageSize().intValue() == 0 ? count / articleModel.getPageSize().intValue() : count / articleModel.getPageSize().intValue() + 1));
        return this.articleDao.queryArticleAll(articleModel);
    }
}